package com.sinoglobal.shakeprize.adapter;

import java.util.List;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.ViewGroup;

import com.sinoglobal.shakeprize.bean.ResponseShakeSessionListItem;
import com.sinoglobal.shakeprize.fragment.SessionItemFragment;
import com.sinoglobal.shakeprize.fragment.SessionItemFragment.SessionStatus;

/**
 * @author temulu
 * @createdate 2015-8-26下午2:30:15
 * @Description 场次详情的adapter
 */
public class ShakeSessionAdapter extends FragmentPagerAdapter {

	private List<ResponseShakeSessionListItem> mData;
	private FragmentManager manager;
	private long systemTime;
	private int position;
	
	public ShakeSessionAdapter(FragmentManager fm) {
		super(fm);
	}

	public ShakeSessionAdapter(FragmentManager fm,List<ResponseShakeSessionListItem> list,long currentTime) {
		super(fm);
		mData=list;
		manager=fm;
		systemTime = currentTime;
	}

	@Override
	public Fragment getItem(final int position) {
		this.position=position;
		return new SessionItemFragment(mData.get(position),mData.size(),systemTime,new SessionStatus() {
			
			@Override
			public void sessionRemindStatus(boolean isRemind) {
				mData.get(position).remind=isRemind;
			}
		});
	}
	

	@Override
	public Object instantiateItem(ViewGroup container, int position) {
		SessionItemFragment itemFragment=(SessionItemFragment) super.instantiateItem(container, position);
		itemFragment.setItem(mData.get(position));
		itemFragment.setSystemTime(systemTime);
		return itemFragment;
	}
	
	@Override
	public int getItemPosition(Object object) {
		return POSITION_NONE;
	}
	
	@Override
	public int getCount() {
		return mData.size();
	}

	public void setList(List<ResponseShakeSessionListItem> list,long currentTime){
		mData=list;
		systemTime = currentTime;
		notifyDataSetChanged();
	}

}
